<?php
declare (strict_types=1);

namespace app\index\controller;

use think\facade\View;
use think\response\Json;
use app\common\model\Draw as DrawModel;
use think\exception\ValidateException;

class Draw extends Base
{

    public function index()
    {
        return View::fetch();
    }

    public function mode()
    {
        return View::fetch();
    }

    public function record()
    {
        return View::fetch();
    }

    public function getList(): Json
    {
        $param = $this->request->param();

        $map = ['uid' => $this->user->id];

        return json(DrawModel::getPageList($map, '*', $param['page'], 20, false));
    }

    public function save(): Json
    {
        $param = $this->request->post('', '', $this->filter);
        try {
            $this->validate($param, 'Draw');
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        }
        return json(DrawModel::add($param, $this->user, $this->system));
    }

}

